package cn.pro.jasmine.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class AppLogin {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入账号：");
        String username = scanner.nextLine();

        System.out.print("请输入密码：");
        String password = scanner.nextLine();

        login(username, password);
    }
    public static void login(String n, String p) throws Exception {
        System.out.println("输入的账号是：" + n);
        System.out.println("输入的密码是：" + p);
        String sql = "SELECT id FROM `user` WHERE username = ?  AND `password` = MD5(?)";
        System.out.println(sql);
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
        String username = "root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, username, password);
        Statement statement = connection.createStatement();
        ResultSet set = statement.executeQuery(sql);

        if (set.next()) {
            System.out.println("登录成功！");
        } else {
            System.out.println("登录失败！");
        }
    }

}


